package com.zyx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyx.annotation.UserLoginToken;
import com.zyx.pojo.DTO.PeopleDTO;
import com.zyx.pojo.People;
import com.zyx.pojo.RespBean;
import com.zyx.service.IPeopleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("//people")
@Api(value = "人事管理模块" ,tags = "web人事管理接口")
public class PeopleController {
    @Autowired
    private IPeopleService peopleService;

    @UserLoginToken
    @GetMapping("/getPeopleList")
    @ApiOperation(value = "获得员工列表信息")
    public RespBean getPeopleList(){
        List<PeopleDTO> list=peopleService.getPeopleList();
        return RespBean.success("成功",list);

    }
    @UserLoginToken
    @PostMapping("/deletePeople")
    @ApiOperation(value = "删除员工")
    public RespBean deletePeopleList(Integer people_id){
        QueryWrapper<People> wrapper = new QueryWrapper();
        wrapper.eq("people_id",people_id);
        if(peopleService.remove(wrapper)){
            return RespBean.success("删除成功");
        }
        return RespBean.success("删除失败");

    }
    @UserLoginToken
    @PostMapping("/addPeople")
    @ApiOperation(value = "添加员工")
    public RespBean addPeopleList(@RequestBody People people){

        if(peopleService.save(people)){
            return RespBean.success("添加成功");
        }
        return RespBean.success("添加失败");

    }
    @UserLoginToken
    @PostMapping("/updatePeople")
    @ApiOperation(value = "修改员工")
    public RespBean updatePeopleList(@RequestBody People people){
        QueryWrapper<People> wrapper = new QueryWrapper();
        wrapper.eq("people_id",people.getPeople_id());
        peopleService.remove(wrapper);

        if(peopleService.save(people)){
            return RespBean.success("修改成功");
        }
        return RespBean.success("修改失败");

    }

}
